﻿Ext.define('TAB.view.user.UserSelectWin', {
    extend: 'Ext.window.Window',
    alias: 'widget.UserSelectWin',
    requires: [
        'TAB.view.user.SimpleUserGrid',
        'TAB.view.user.ConditionForm'
    ],
    width: 760,
    height: 575,
    resizable: false,
    title: '快速选择用户',
    layout: {
        type: 'table',
        columns: 2
    },
    modal: true,

    initComponent: function () {
        var me = this;
        var userViewMappingName = 'SM010-V1';
        var userGrid = Ext.create('TAB.view.user.SimpleUserGrid', {
            border: false,
            height: 515,
            width: 500
        });
        var userSelectFields = "FID,FREALNAME,FNAME,FSEX,DEPARTMENTNAME,FDUTYNAME";
        userGrid.store.proxy.extraParams.mn2 = "GetByComplexCondition";
        userGrid.store.proxy.extraParams.data = Ext.encode({
            TableName: userViewMappingName,
            OrderFields: 'FSORT',
            SelectFields: userSelectFields,
            Condition: {
                FIsDeleted: 0
            }
        });
        userGrid.store.load();
        var conditionForm = Ext.create('TAB.view.user.ConditionForm', {
            border: false,
            btnQuery: function (values) {
                if (values.length > 0) {
                    var data = {
                        TableName: userViewMappingName,
                        OrderFields: 'FSORT',
                        SelectFields: userSelectFields,
                        Condition: {
                            FIsDeleted: 0
                        },
                        ComplexCondition: Ext.encode(values)
                    };
                    userGrid.store.proxy.extraParams.data = Ext.encode(data);
                }
                else {
                    var data = {
                        TableName: userViewMappingName,
                        OrderFields: 'FSORT',
                        Condition: {
                            FIsDeleted: 0
                        }
                    };
                    userGrid.store.proxy.extraParams.data = Ext.encode(data);
                }
                userGrid.store.loadPage(1);
            }
        });

        me.items = [{
            rowspan: 2,
            //border: false,
            margin: '5 1 2 5',
            height: 515,
            items: conditionForm,
            width: 230
        }, {
            items: userGrid,
            //border: false,
            margin: '5 2 2 1',
            height: 515,
            width: 500
        }];

        //这个重要，不能忘记了
        me.callParent(arguments);

    } //end initComponent
});